package com.itheima.reggie.controller;

import com.itheima.reggie.common.R;
import com.itheima.reggie.entity.Orders;
import com.itheima.reggie.entity.User;
import com.itheima.reggie.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

@RequestMapping("/order")
@RestController
public class OrderController {
    
    @Autowired
    private OrderService orderService;
    
    
    /**
     * 提交订单
     * @param orders
     * @return
     */
    @PostMapping("/submit")
    public R add(@RequestBody Orders orders , HttpSession session){
        
        //1. 调用service
        User user = (User) session.getAttribute("user");
        int row = orderService.add(orders ,  user);
        
        //2. 判定
        if(row >0 ){
            return R.success("提交订单成功！");
        }else{
            return R.error("提交订单失败！");
        }
    }
}
